<?php
	//mysql connect info
	$MYSQL_CONNECT_HOST = "localhost";
	$MYSQL_CONNECT_NAME = "root";
	$MYSQL_CONNECT_PASS = "";
	$USE_DATABASE = "mf001";
	$MYSQL_ENCODE_CHARSET = "utf8";
	
	
	$MYSQL_CONNECT_HOST_EN = "101.227.68.5:10086";
	$MYSQL_CONNECT_NAME_EN = "root";
	$MYSQL_CONNECT_PASS_EN = "netban2015mysql!@#";
	$USE_DATABASE_EN = "netban_en_admin";
	$MYSQL_ENCODE_CHARSET_EN = "utf8";
	
	function open_mysql_connect(){
		global $MYSQL_CONNECT_HOST;
		global $MYSQL_CONNECT_NAME;
		global $MYSQL_CONNECT_PASS;
		global $USE_DATABASE;
		global $MYSQL_ENCODE_CHARSET;
		$dbcon = @mysql_connect( $MYSQL_CONNECT_HOST, $MYSQL_CONNECT_NAME, $MYSQL_CONNECT_PASS );

		if( !$dbcon ){
			echo "Unable to connect to the database server at now. Stacktrace:" . mysql_error();
		}
		if( !mysql_select_db( $USE_DATABASE , $dbcon ) ){
			echo "Unable to select database of '" . $USE_DATABASE . "' to the database server at now. Stacktrace:" . mysql_error();
		}
		mysql_query( "set names '" . $MYSQL_ENCODE_CHARSET . "'" );

		return $dbcon;
	}
	
	function open_mysql_connect_en(){
		global $MYSQL_CONNECT_HOST_EN;
		global $MYSQL_CONNECT_NAME_EN;
		global $MYSQL_CONNECT_PASS_EN;
		global $USE_DATABASE_EN;
		global $MYSQL_ENCODE_CHARSET_EN;
		$dbcon = @mysql_connect( $MYSQL_CONNECT_HOST_EN, $MYSQL_CONNECT_NAME_EN, $MYSQL_CONNECT_PASS_EN );

		if( !dbcon ){
			echo "Unable to connect to the database server at now. Stacktrace:" . mysql_error();
		}
		if( !mysql_select_db( $USE_DATABASE_EN , $dbcon ) ){
			echo "Unable to select database of '" . $USE_DATABASE_EN . "' to the database server at now. Stacktrace:" . mysql_error();
		}
		mysql_query( "set names '" . $MYSQL_ENCODE_CHARSET_EN . "'" );

		return $dbcon;
	}

	function db_exec_fetch($sql, $callback,$dcon='open_mysql_connect'){
		$dcon(); //open the mysql connection
		$result = @mysql_query($sql);
		while( $row = mysql_fetch_array($result,MYSQL_ASSOC) ):
			$callback($row);
		endwhile;
		@mysql_close();
	}

	function db_exec_query($sql,$dcon='open_mysql_connect'){
		
		$dcon(); //open the mysql connection
		$result = @mysql_query($sql);
		$ret = array();
		while( $row = mysql_fetch_array($result,MYSQL_ASSOC) ):
			array_push($ret, $row);
		endwhile;
		@mysql_close();
		return $ret;
	}

	function db_exec_update($sql,$back=0,$dcon='open_mysql_connect'){
		$dcon(); //open the mysql connection
		@mysql_query($sql);//执行语句
		$result =mysql_affected_rows();//返回影响的结果
		$insert_id= mysql_insert_id(); 
		if($back==0)
		{
			$ret = $result == 1;
		}
		else
		{
			$ret =$insert_id;
		}
		@mysql_close();
		return $ret;
	}

?>